package com.springboot.auth.authorization.exception;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.oauth2.common.exceptions.OAuth2Exception;
import org.springframework.security.oauth2.provider.error.WebResponseExceptionTranslator;
import org.springframework.stereotype.Component;

/**
 * Created by ZengJian on 2021/2/3 0003 上午 9:22
 */
@Component("customWebResponseExceptionTranslator")
public class CustomWebResponseExceptionTranslator implements WebResponseExceptionTranslator {

    @Override
    public ResponseEntity<OAuth2Exception> translate(Exception e) throws Exception {

        OAuth2Exception oAuth2Exception = (OAuth2Exception) e;
        return ResponseEntity
                .status(HttpStatus.OK)
                .body(new CustomOauthException(oAuth2Exception));
    }
}

//public class CustomWebResponseExceptionTranslator implements WebResponseExceptionTranslator<OAuth2Exception> {
//
//    @Override
//    public ResponseEntity<OAuth2Exception> translate(Exception e) {
//
//        OAuth2Exception oAuth2Exception = (OAuth2Exception) e;
//        return ResponseEntity.status(oAuth2Exception.getHttpErrorCode())
//                .body(new CustomOauthException(oAuth2Exception));
//    }
//}
